import {Obj} from "@/pages/wordPage/src/interface/Obj";
import screen from "@/pages/wordPage/src/screen";
import utils from "@/pages/wordPage/src/utils";
import message from './message'
import config from "@/config";
import setting from "@/setting";

export  default class des extends Obj{
    name="描述"
    maxLife=3000;
    maxDesLength=20;//最大解释字数
    des=""
    content;
    fontSize=setting.value.fontSize;
    maxLifeMill=3000;
    zIndex=2;
    width=600;
    height=1;
    constructor(x,y,content,des) {
        super();
        this.x=x;
        this.y=y;
        this.maxLife=Date.now()+this.maxLifeMill;
        this.des=des;
        this.content=content;
        this.width=utils.calculateTextWidth(this.des,this.fontSize)+20
        this.height=this.fontSize*2;
    }
    draw(p) {
        super.draw(p);
        if (Date.now()>this.maxLife){
            this.destroy();
            return;
        }
        p.blendMode(p.BLEND);

        let opc=(this.maxLife-Date.now());

         opc=opc/this.maxLifeMill;
        p.fill(`rgba(95,255,4,${opc})`)
        p.rectMode(p.CORNER);
        p.strokeWeight(5);
        p.stroke(`rgba(1,1,1,${opc})`);
        let trymax=30;
        let currentTry=0;
        while(currentTry<trymax){
            currentTry++
            if (currentTry>=trymax){
                new message(this.des);
                return;
            }
            // console.log("scan",utils.isOutOfBounds(this, screen.width, screen.height))
            if (utils.isOutOfBounds(this, screen.width, screen.height)) {
                utils.adjustToBounds(this,screen.width, screen.height)
            }else{
                break;
            }
        }


        p.textAlign(p.CENTER,p.CENTER);
        // p.rect(this.x,this.y,this.width,this.height)

        p.text(this.des,this.x,this.y,this.width,this.height)



    }
    destroy() {
        return super.destroy();
    }
}